1. /* sdmrefrm.cpp by K.Tsuru */
  2. // fuction ID = 314 DRADIX, BRADIX
  3. /***************************************************************************
  4. SDouble and SDecimal classes
  5. It reforms int an appropriate form considering the present operation mode
  6. (fixed or floating point mode).
  7. It adjusts the size of figure[] and removes lower zeros.
  8. **************************************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. void SDouble::Reform(int id){
  13. if(abs(rdxExp) > DRADIX_EXP_MAX) SetError(TOO_LARGE_EXP,"SD",id);
  14. if(SNSign() == 0){
  15. if(!IsPointFixed()) DoCutDown(); //cutting down lower zeros
  16. return;
  17. }
  18. uint cms = CurrentMaxSize();
  19. if(Type() == BIN_DEC){
  20. #ifndef NDEBUG
  21. assert(rdxExp == 0);
  22. #endif
  23. if(aHead < cms) return;
  24. figure.clear(cms); //cutting down over figures
  25. while( !figure[aHead] && (aHead > aTail)) aHead--;
  26. if( (aHead == aTail) && !figure[aHead]) SetSign(0);
  27. return;
  28. }
  29. /*
  30. SDouble variable here
  31. When figure[0]>0 by carry, in either mode it makes figure[0]=0 by the moving
  32. figures.
  33. */
  34. int f = (int)aTail; //top position
  35. int m; //the quantity of moving figures
  36. // f+m : top position after moving figures
  37. if( IsPointFixed() ){ //fixed point mode
  38. /*
  39. The quantity of moving figures in the fixed point mode is evaluated as
  40. x*R^e = x*R^(e-fe)*R^(fe) = {x*R^(-m)}*R^(fe)
  41. m = fe - e
  42. */
  43. m = fixedExp - rdxExp;
  44. if(f + m >= (int)cms ) { SetZero(); return; }
  45. //When f+m <=0,i.e.the value of fixed exponent cannot be taken as "fe",
  46. //the top figure is placed at first position figure[1].
  47. if(f + m <= 0) m = f ? (1 - f) : 1; //m=1 for f=0(figure[0]>0)
  48. } else m = 1 - f; //In the floating point mode,it sets the top figure at first position.
  49. if(m){ SetRdxExp(rdxExp + m); ShiftArray(m); }
  50. //It cutss down extra figures.
  51. if( aHead >= cms ){
  52. //It is better to include the rouning off, but the processing becomes complex.
  53. figure.clear(cms); // set figure[i] = 0 for i >= cms
  54. if(aTail >= cms){ // cms <= aTail <= aHead
  55. rdxExp = 0; SetSign(0); //All the elements of figure[] are zero.
  56. } else { // figure[aTail] != 0
  57. aHead = cms - 1u;
  58. while( !figure(aHead) ) aHead--; //Maybe there are zeros in intermediate region.
  59. }
  60. }
  61. //It cuts down the figures which has zero.
  62. uint fs = figure.size();
  63. if(IsPointFixed()){
  64. uint ms = ceilpow2( MaxSize() );//Not CurrentMaxSize(), because the size must be fixed.
  65. //If the effective figures decreased, it cuts down the size.
  66. if(fs > ms) figure.size(ms, 1); // cms <= ms
  67. } else if( 2u*(aHead+1u) <= fs ) DoCutDown();
  68. }

sdmrefrm.cpp : last modifiled at 2015/11/25 20:19:52(2,628 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).